/**
 * author      : dormi330
 * date        : 2018/7/17
 * description : TODO
 */

package com.deep.trade.application.refund;

import com.deep.trade.adaptor.required.member.Member;
import com.deep.trade.adaptor.required.member.MemberService;
import com.deep.trade.domain.refund.RefundOrder;
import com.deep.trade.domain.refund.RefundQueryRepository;
import com.deep.trade.refund.dto.OutDtoRefundType;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RefundQueryService {

    @Autowired
    private RefundQueryRepository refundQueryRepository;

    @Autowired
    private MemberService memberService;

    public List<OutDtoRefundType> listAllRefundType() {
        return refundQueryRepository.allRefundType().stream().map(refundType -> {
            OutDtoRefundType outDtoRefundType = new OutDtoRefundType();
            BeanUtils.copyProperties(refundType, outDtoRefundType);
            return outDtoRefundType;
        }).collect(Collectors.toList());
    }

    public PageInfo<RefundOrder> refundListOfMember(int pageNum, int pageSize) throws Exception {
        Member member = memberService.memberOfToken();
        return refundQueryRepository.listRefundApplyOfMember(member.getId(), pageNum, pageSize);
    }

    public PageInfo<RefundOrder> refundListOfTenant(int pageNum, int pageSize) throws Exception {
        return refundQueryRepository.listRefundApplyOfTenant(pageNum, pageSize);
    }

    public PageInfo<RefundOrder> refundListOfSeller(String sellerId, int pageNum, int pageSize) throws Exception {
        return refundQueryRepository.listRefundApplyOfSeller(sellerId, pageNum, pageSize);
    }
}
